<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- portingcppapps_toqt5.qdoc -->
  <title>Porting C++ Applications to Qt 5 | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Porting C++ Applications to Qt 5</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#related-topics">Related Topics</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Porting C++ Applications to Qt 5</h1>
<span class="subtitle"></span>
<!-- $$$portingcppapp.html-description -->
<div class="descr"> <a name="details"></a>
<p>This topic talks about the Qt Widgets changes in Qt 5. The following step-by-step instructions take you through the changes required to port the <a href="../qtwidgets/qtwidgets-animation-animatedtiles-example.html">Animated Tiles</a> application to Qt 5:</p>
<ol class="1" type="1"><li>Open the Animated Tiles project using Qt Creator.</li>
<li>Edit <code>main.cpp</code> and replace the <code>#include &lt;QtGui&gt;</code> instance with <code>#include &lt;QtWidgets&gt;</code>. The Perl-script <code>fixqt4headers.pl</code> can be used to scan the source files of a project and perform the replacements.</li>
<li>Edit the <code>animatedtiles.pro</code> and add <code>QT += widgets</code> towards the end of the file.<p><b>Note: </b><a href="../qtgui/qtgui-index.html">Qt GUI</a> is included by default in all Qt applications unless excluded using the <code>QT -= gui</code> directive in the <code>qmake</code> project file.</p></li>
<li>Save the changes and run the application.</li>
</ol>
<p>Once you see the application running, check whether it behaves as expected.</p>
<p class="centerAlign"><img src="images/animatedtiles_snapshot.png" alt="&quot;A snapshot of the \c animatedtiles application running on Ubuntu v12.04&quot;" /></p><p>It is also possible to keep the project compiling with Qt 4 and Qt 5. This requires:</p>
<ol class="1" type="1"><li>Omitting the module name from all includes by running the <code>fixqt4headers.pl</code> script with the <code>--strip-modules</code> option.</li>
<li>Adding scopes depending on the version of Qt to the <code>.pro</code> files:<pre class="cpp">

  greaterThan(QT_MAJOR_VERSION<span class="operator">,</span> <span class="number">4</span>): QT <span class="operator">+</span><span class="operator">=</span> widgets

</pre>
</li>
<li>Introducing <code>#if</code> scopes around code using modified API:<pre class="cpp">

  <span class="preprocessor">#if QT_VERSION &gt;= 0x050000</span>
      headerView<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="type"><a href="../qtwidgets/qheaderview.html">QHeaderView</a></span><span class="operator">::</span>ResizeToContents);
  <span class="preprocessor">#else</span>
      headerView<span class="operator">-</span><span class="operator">&gt;</span>setResizeMode(<span class="type"><a href="../qtwidgets/qheaderview.html">QHeaderView</a></span><span class="operator">::</span>ResizeToContents);
  <span class="preprocessor">#endif</span>

</pre>
</li>
</ol>
<p>if you are using Qt <a href="../qtwebengine/qtwebengine-3rdparty-webkit.html">WebKit</a>, see <a href="../qtwebengine/qtwebenginewidgets-qtwebkitportingguide.html">Qt WebKit to Qt WebEngine</a> porting instructions.</p>
<a name="related-topics"></a>
<h2 id="related-topics">Related Topics</h2>
<ul>
<li><a href="sourcebreaks.html">C++ API Changes</a></li>
<li><a href="portingqmlapp.html">Porting QML Applications to Qt 5 Example</a></li>
<li><a href="qtexamplesandtutorials.html">Qt Examples And Tutorials</a></li>
</ul>
</div>
<!-- @@@portingcppapp.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
